package com.ruoyi.framework.security.token;


// 自定义AuthenticationToken
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class NoPwdAuthenticationToken implements Authentication {

    private final Object principal;
    private String credentials;

    public NoPwdAuthenticationToken(Object principal, String credentials) {
        this.principal = principal;
        this.credentials = credentials;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return ((UserDetails) principal).getAuthorities();
    }

    @Override
    public Object getCredentials() {
        return credentials;
    }

    @Override
    public Object getDetails() {
        return credentials;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

    @Override
    public boolean isAuthenticated() {
        return credentials == null || !credentials.isEmpty();
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (isAuthenticated) {
            this.credentials = null;
        } else {
            this.credentials = "N/A";
        }
    }

    @Override
    public String getName() {
        return null;
    }

}
